function getReaderInfo() {
    $.ajax({
        url : '/reader/getReaderInfo',
        type : 'POST',
        success : function (res) {
            $("#readId").text(res?.readId || "");
            $("#readName").text(res?.readName || "");
            $("#readSex").text(res?.readSex || "");
            $("#readPassword").text(res?.readPass || "");
            $("#readTel").text(res?.readTel || "");
            $("#readEmail").text(res?.readMail || "");
            $("#rbSum").text(res?.rbSum || "");
            $("#rbRead").text(res?.rbRead || "");
        },
        error : function () {
            alert("请求出错");
        }
    })
}


document.addEventListener("DOMContentLoaded", function () {
    var readId = $("#readId").text();
    var inputreadId1 = document.getElementById("inputreadId1");
    var inputreadId = document.getElementById("inputreadId");
    inputreadId1.value = readId;
    inputreadId.value = readId;
});

$("#showPopup").click(function () {
    var inputreadName = document.getElementById("inputreadName");
    var inputreadSex = document.getElementById("inputreadSex");
    var inputreadTel = document.getElementById("inputreadTel");
    var inputreadMail = document.getElementById("inputreadMail");
    inputreadName.value = $("#readName").text();
    inputreadSex.value = $("#readSex").text();
    inputreadTel.value = $("#readTel").text();
    inputreadMail.value = $("#readMail").text();
});

$("#btn-update").click(function (event) {
    event.preventDefault();
    var readId = $("#inputreadId").val();
    var readName = $("#inputreadName").val();
    var readSex = $("#inputreadSex").val();
    var readTel = $("#inputreadTel").val();
    var readMail = $("#inputreadMail").val();
    $.ajax({
        url : '/reader/updateReader',
        type : 'POST',
        data : {
            readId : readId,
            readName : readName,
            readSex : readSex,
            readTel : readTel,
            readMail : readMail
        },
        success : function (res) {
            if(res === 'success'){
                alert('修改成功');
                getReaderInfo();
            }else if(res ==='false'){
                alert('修改失败,请重试');
            }else {
                alert('未知的返回结果，请联系管理员！');
            }
        },
        error : function () {
            alert("请求出错");
        }
    })
})

$("#btn-delete").click(function (event) {
    event.preventDefault();
    var readId = $("#inputreadId1").val();
    $.ajax({
        url : '/reader/deleteReader',
        type : 'POST',
        data : {
            readId : readId
        },
        success : function (res) {
            if(res === 'success'){
                alert('注销成功');
                window.location.href = "./loginHtml";
            }else if(res ==='false'){
                alert('注销失败,请重试');
            }else {
                alert('未知的返回结果，请联系管理员！');
            }
        },
        error : function () {
            alert("请求出错");
        }
    })
})



